// OpenGLView.h : interface of the COpenGLView class
//
/////////////////////////////////////////////////////////////////////////////

#if !defined(AFX_OPENGLVIEW_H__5857316D_EA60_11D5_9FD5_00D0B718E2CD__INCLUDED_)
#define AFX_OPENGLVIEW_H__5857316D_EA60_11D5_9FD5_00D0B718E2CD__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000


#include "gl\GL.h"      // Include the standard OpenGL  headers
#include "gl\GLU.h"     // Add the utility library
//#include "gl\glut.h"
//#include "gl\freeglut_std.h"


#include "ColorRGBA.h"
#include "Light.h"
#include "atltypes.h"
#include "Transformation.h"
#include <map>

typedef enum {MODE_CAMERA, MODE_OBJECT} ModeType;


class COpenGLView : public CView
{
protected: // create from serialization only
	COpenGLView();
	DECLARE_DYNCREATE(COpenGLView)

// Attributes
public:
	COpenGLDoc* GetDocument();

// Operations
public:

private:
	int     m_nAxis;                    // Axis of Action, X Y Z or Free Control
    int     m_nPrevAxis;                // Previous axis that was used
	int     m_nAction;                  // Rotate, Translate, Scale
	int     m_nView;                    // Orthographic, perspective
	bool    m_bIsPerspective;           // is the view perspective
	
	CString m_strItdFileName;           // file name of IRIT data

	int     m_nLightShading;            // shading: Flat, Goraud

	double  m_lMaterialAmbient;         // The Ambient in the scene
	double  m_lMaterialDiffuse;         // The Diffuse in the scene
	double  m_lMaterialSpecular;        // The Specular in the scene
	int     m_nMaterialCosineFactor;	// The cosine factor for the specular

    unsigned int actionAxisBitVector;

    bool    m_bShowVertexNormals;
    bool    m_bShowFaceNormals;
    bool    m_bShowBoundingBox;

	LightParams m_lights[MAX_LIGHT];    //configurable lights array
	LightParams m_ambientLight;         //ambient light (only RGB is used)

    CPoint m_InitialMouseCoord;         // updated by WM_LBUTTONDOWN
    CPoint m_LastMouseCoord;            // updated by WM_LBUTTONDOWN

    float  m_fRotMouseSensitivity;      // values between ...Min and ...Max
    float  m_fTraMouseSensitivity;      //
    float  m_fScaMouseSensitivity;      // 

    float  m_fRotMouseSensitivityFactor;// empiric values that are used to
    float  m_fTraMouseSensitivityFactor;// normalize the Mouse Settings Dialog
    float  m_fScaMouseSensitivityFactor;// return values

    int    m_nMode;                     // MODE_CAMERA or MODE_OBJECT

    ColorRGBA objectColor;
    ColorRGBA backgroundColor;
    ColorRGBA vertexNormalColor;
    ColorRGBA faceNormalColor;
    ColorRGBA boundingBoxColor;

    bool overrideWireFrameColor;

	std::map<int, Transformation*> m_transforms;


#pragma message("TODO: Implement keyboard control.")

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(COpenGLView)
	public:
	virtual void OnDraw(CDC* pDC);      // overridden to draw this view
	virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
	protected:
	//}}AFX_VIRTUAL

// Implementation
public:
	virtual ~COpenGLView();
#ifdef _DEBUG
	virtual void AssertValid() const;
	virtual void Dump(CDumpContext& dc) const;
#endif

protected:
	BOOL InitializeOpenGL();
	BOOL SetupPixelFormat(PIXELFORMATDESCRIPTOR* pPFD=0); // the '=0' was added
	BOOL SetupViewingFrustum(void);
	BOOL SetupViewingOrthoConstAspect(void);

	virtual void RenderScene();


	HGLRC  m_hRC;               // holds the Rendering Context
	CDC*   m_pDC;               // holds the Device Context
	int    m_WindowWidth;       // hold the windows width
	int    m_WindowHeight;      // hold the windows height
	double m_AspectRatio;       // hold the fixed Aspect Ration

	void updateSensitivity( float rotate, float trans, float scale );

	void initializeTransformations( );

private:
	void drawAxes( );
    void resetView( );


// Generated message map functions
protected:
	//{{AFX_MSG(COpenGLView)
	afx_msg BOOL OnEraseBkgnd(CDC* pDC);
	afx_msg int  OnCreate(LPCREATESTRUCT lpCreateStruct);
	afx_msg void OnDestroy();
	afx_msg void OnSize(UINT nType, int cx, int cy);
	afx_msg void OnFileLoad();
	afx_msg void OnViewOrthographicView();
	afx_msg void OnUpdateViewOrthographicView(CCmdUI* pCmdUI);
	afx_msg void OnViewPerspectiveView();
	afx_msg void OnUpdateViewPerspectiveView(CCmdUI* pCmdUI);
	afx_msg void OnActionRotate();
	afx_msg void OnUpdateActionRotate(CCmdUI* pCmdUI);
	afx_msg void OnActionScale();
	afx_msg void OnUpdateActionScale(CCmdUI* pCmdUI);
	afx_msg void OnActionTranslate();
	afx_msg void OnUpdateActionTranslate(CCmdUI* pCmdUI);
	afx_msg void OnAxisX();
	afx_msg void OnUpdateAxisX(CCmdUI* pCmdUI);
	afx_msg void OnAxisY();
	afx_msg void OnUpdateAxisY(CCmdUI* pCmdUI);
	afx_msg void OnAxisZ();
	afx_msg void OnUpdateAxisZ(CCmdUI* pCmdUI);
	afx_msg void OnLightShadingFlat();
	afx_msg void OnUpdateLightShadingFlat(CCmdUI* pCmdUI);
	afx_msg void OnLightShadingGouraud();
	afx_msg void OnUpdateLightShadingGouraud(CCmdUI* pCmdUI);
	afx_msg void OnLightConstants();
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP( )

public:
    afx_msg void OnLButtonDown( UINT nFlags, CPoint point );
    afx_msg void OnMouseMove( UINT nFlags, CPoint point );
    afx_msg void OnOptionsMouseSettings( );
    afx_msg void OnOptionsPerspectiveSettings( );
    afx_msg void OnViewShowVertexNormals( );
    afx_msg void OnUpdateViewShowVertexNormals( CCmdUI *pCmdUI );
    afx_msg void OnModeCamera( );
    afx_msg void OnUpdateModeCamera( CCmdUI *pCmdUI );
    afx_msg void OnModeObject( );
    afx_msg void OnUpdateModeObject( CCmdUI *pCmdUI );
    afx_msg void OnViewShowBoundingBox( );
    afx_msg void OnUpdateViewShowBoundingBox( CCmdUI *pCmdUI );
    afx_msg void OnViewShowFaceNormals( );
    afx_msg void OnUpdateViewShowFaceNormals( CCmdUI *pCmdUI );
    afx_msg void OnViewResetView( );
    afx_msg void OnOptionsColorSettings( );
    afx_msg void OnAxisFreeControl();
    afx_msg void OnUpdateAxisFreeControl(CCmdUI *pCmdUI);
};

#ifndef _DEBUG  // debug version in OpenGLView.cpp
inline COpenGLDoc* COpenGLView::GetDocument( )
   { return (COpenGLDoc*)m_pDocument; }
#endif

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_OPENGLVIEW_H__5857316D_EA60_11D5_9FD5_00D0B718E2CD__INCLUDED_)
